<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>二手交易平台</title>
  <link rel="stylesheet" type="text/css" href="/ssm/consumer/res/static/css/main.css">
  <link rel="stylesheet" type="text/css" href="/ssm/consumer/res/layui/css/layui.css">
  <script type="text/javascript" src="/ssm/consumer/res/layui/layui.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
 <style type="text/css">
  	.userNotLogin{
  		display: none;
  	}
  </style>
</head>
<body>

  <div class="site-nav-bg">
    <div class="site-nav w1200">
      <p class="sn-back-home">
        <i class="layui-icon layui-icon-home"></i>
        <a href="/ssm/consumer/index.html">首页</a>
      </p>
      <div class="sn-quick-menu">
        	<div class="userLogin">
        		<div class="login"><a href="/ssm/consumer/login.html">登录</a></div>
        		<div class="login"><a href="/ssm/consumer/register.html">注册</a></div>
        	</div>
        	<div class="userNotLogin">
        		<div class="login"><a href="/ssm/consumer/userInfo.html" id="username">用户名</a></div>
        		<div class="login"><a href="JavaScript:loginOut();">退出</a></div>
        		<div class="login"><a href="/ssm/consumer/myOrder.html">我的订单</a></div>
        		<div class="sp-cart"><a href="/ssm/consumer/shopcart.html">购物车</a></div>
        	</div>
      </div>
    </div>
  </div>



   <div class="header">
    <div class="headerLayout w1200">
      <div class="headerCon">
        <h1 class="mallLogo">
          <a href="/ssm/consumer/index.html" >
            <img src="/ssm/consumer/res/static/img/logo.png">
          </a>
        </h1>
        <div class="mallSearch">
          <form action="" class="layui-form" novalidate>
            <input type="text" id="keyword" name="title" required  lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入需要的商品">
            <button class="layui-btn" id="searchbutton" lay-filter="formDemo" onclick="return false">
                <i class="layui-icon layui-icon-search"></i>
            </button>
            <input type="hidden" name="" value="">
          </form>
        </div>
      </div>
    </div>
  </div>


  <div class="content content-nav-base shopcart-content">
    <div class="main-nav">
      <div class="inner-cont0">
        <div class="inner-cont1 w1200">
          <div class="inner-cont2">
            <a href="#" class="active">我的订单</a>
          </div>
        </div>
      </div>
    </div>
    <div class="banner-bg w1200">
    </div>
    <div class="cart w1200">
      <div class="cart-table-th">
        <div class="th th-price">
          <div class="th-inner">
            订单号
          </div>
        </div>
        <div class="th th-sum">
          <div class="th-inner">
            订单商品
          </div>
        </div>
        <div class="th th-amount">
          <div class="th-inner">
            订单总额
          </div>
        </div>
        <div class="th th-sum">
          <div class="th-inner">
            收货人信息
          </div>
        </div>
        <div class="th th-sum">
          <div class="th-inner">
            状态
          </div>
        </div>
        <div class="th th-sum">
          <div class="th-inner">
            操作
          </div>
        </div>
      </div>
      <div class="OrderList">
        <div class="order-content" id="list-cont" style="border-bottom: 1px solid #ececee;">
         </div>
      </div>
    </div>
  </div>

<script type="text/javascript">
  layui.config({
    base: '/ssm/consumer/res/static/js/util/' //你存放新模块的目录，注意，不是layui的模块目录
  }).use(['mm','jquery','element'],function(){
    var mm = layui.mm,$ = layui.$,element = layui.element;

});
</script>

<script type="text/javascript" src="/ssm/consumer/js/jquery-1.4.3.min.js"></script>
<script type="text/javascript">

$("#searchbutton").click(function Search(){
	location.href="/ssm/consumer/index.html?pname="+$("#keyword").val();
	return false;
})

$("#keyword").val(getQueryString('pname'));


var info;
getUserInfo();
function  getUserInfo(){
    $.ajax({
        url:"/ssm/consumer/loginInfo.do",
        type:"POST",
        dataType:"json",
        success:function(data){
        	info = data.body
           if(info!=null){
        	   $(".userLogin").hide();
        	   $("#username").text(info.real_name);
        	   $(".userNotLogin").show();
           }else{
           }
        } 
    })
 }
 
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]); return null;
} 

function loginOut(){
	$.post('/ssm/consumer/logout.do',function(){
		
		location.href="/ssm/consumer/login.html";
	})
}


//获取购物车列表
getShopCart();
function getShopCart(){
	var postData = {
	}
	$.post('/ssm/order/queryListByConsumer.do',postData,function(data){
		console.log(data);
		for(var idx in data.body){
			var orderItem = data.body[idx];
			var productItem = data.body[idx].product;
			var item = '<ul class="item-content layui-clear" style="height: 48px;padding: 29px 0;padding-top: 8px;">';
	            item+=' <li class="th th-price" style="left: 0px;">';
	            item+=' <div class="item-cont">';
	            item+=' <div class="text">';
	            item+=' <div class="title">'+orderItem.orderNo+'</div>';
	            item+=' </div>';
	            item+=' </div>';
	            item+=' </li>';
	            var products="";
	            item+=' <li class="th th-sum">';
	            item+=' <storang class="th-su" style="width:200px;"'+products+' </storang>';
	            item+=' </li>';
	            item+=' <li class="th th-amount" style="margin-left: 200px;">';
	            item+=' <span class="th-su">'+orderItem.money+' </span>';
	            item+=' </li>';
	            item+=' <li class="th th-sum" style="text-align:left">';
	            item+=' <storang class="sum">'+orderItem.recipients+' </storang>';
	            item+=' | <storang class="sum">'+orderItem.tel+' </storang>';
	            item+=' | <storang class="sum">'+orderItem.address+' </storang>';
	            item+=' </li>';
	            item+=' <li class="th th-sum">';
	            var state = "";
   				if(orderItem.state == 1){
   					state='待发货';
				}else if(orderItem.state==2){
					state='已发货';
				}else if(orderItem.state==3){
					state='已完成';
				}else if(orderItem.state == 0){
					state='已取消';
				}
	            item+=' <storang class="th-su">'+state+' </storang>';
	            item+=' </li>';
	            item+=' <li class="th">';
	            if(orderItem.state == 1){
						item+='<a style="color:red;" href="javascript:updateState(\''+orderItem.oid+'\',\'0\');">取消订单</a>';
					}else if(orderItem.state==2){
						item+='<a style="color:green;" href="javascript:updateState(\''+orderItem.oid+'\',\'3\');">确认收货</a>';
					}
	            item+=' </li>';
            	item+=' </ul>';
				$("#list-cont").append(item);
				for(var key in orderItem.orderitems){
					var product = orderItem.orderitems[key];
					item = '<ul class="item-content layui-clear" style="height: 48px;padding: 29px 0;padding-top: 8px;">';
		            item+=' <li class="th th-price" style="left: 0px;">';
		            item+=' <div class="item-cont">';
		            item+=' <div class="text">';
		            item+=' <div class="title"></div>';
		            item+=' </div>';
		            item+=' </div>';
		            item+=' </li>';
		            item+=' <li class="th th-sum" style="margin-left: 200px;">';
		            item+=' <storang class="th-su">'+(product.product.pname)+' </storang>';
		            item+=' </li>';
		            item+=' <li class="th th-amount">';
		            item+=' <span class="th-su">数量：'+product.buynum+'</span>';
		            item+=' </li>';
		           	if(product.state==1){
		           	 	item+=' <li class="th th-sum" style="text-align:left">';
		            	item+=' <storang class="sum">评分：'+product.score+'</storang>';
		            	item+=' </li>';
		            	item+=' <li class="th th-sum">';
		            	item+=' <storang class="th-su">评价:'+product.comment+'</storang>';
		            	item+=' </li>';
		           	}
		            item+=' <li class="th" style="margin-left: 400px;">';
		            if(orderItem.state==3&&product.state==0){
							item+='<a style="color:green;" href="/ssm/consumer/pingjia.html?itemid='+product.itemid+'">评论</a>';
					}
		            item+=' </li>';
	            	item+=' </ul>';
					$("#list-cont").append(item);
					
				}
		}
		if(data.body.length>0){
			$("#goOrder").show();
		}
	
	})
}

function updateState(oid,state){
	var postData = {
			oid:oid,
			state:state,
			
	}
	$.post('/ssm/order/updateStatus.do',postData,function(data){
		location.reload();
	})
	
}
</script>
</body>
</html>